package com.krinko.controller;

import com.krinko.pojo.Category;
import com.krinko.pojo.Result;

import com.krinko.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping
    public Result addCategory(@RequestBody @Validated Category category) {

        categoryService.addCategory(category);
        return Result.success();

    }
    @GetMapping
    public Result<List<Category>> list(){

        List<Category> ls = categoryService.list();
        return Result.success(ls);
    }
    @GetMapping("/detail")
    public Result<Category> detail(Integer id) {
        Category category = categoryService.findById(id);
        return Result.success(category);
    }
    @PutMapping
    public Result update(@RequestBody @Validated Category category) {
        categoryService.update(category);
        return Result.success();

    }
}
